﻿<%

Class Cls_Sitelink

	Dim vID
	Dim vText
	Dim vDescription
	Dim vLink
	Dim vOrder
	Dim vReplace
	Dim vTarget
	Dim vState
	Dim LastError

	Private Sub Class_Initialize()
		Call ChkLogin("sitelink")
		Call Initialize()
	End Sub

	Private Sub Class_Terminate()
		Call Initialize()
	End Sub

	Public Function Initialize()
		vID = 0
		vText = ""
		vDescription = ""
		vLink = ""
		vOrder = 1
		vReplace = 1
		vTarget = 1
		vState = 1
	End Function

	Public Function GetValue()
		vText = Request.Form("oText")
		vText = Replace(vText," ","")
		vText = Replace(vText,"'","")
		vDescription = Request.Form("oDescription")
		vDescription = Replace(vDescription," ","")
		vDescription = Replace(vDescription,"'","") 
		vLink = Request.Form("oLink")
		vOrder = Request.Form("oOrder")
		vReplace = Request.Form("oReplace")
		vTarget = Request.Form("oTarget")
		vState = Request.Form("oState")
		If Len(vText) < 1 Or Len(vText) > 20 Then LastError = "链接文字的长度请控制在 1 至 20 位" : GetValue = False : Exit Function
		If Len(vDescription) = 0 Then vDescription = vText
		If Len(vDescription) > 100 Then LastError = "链接描述的长度请控制在 100 位以内" : GetValue = False : Exit Function
		If Len(vLink) < 1 Or Len(vLink) > 250 Then LastError = "链接地址的长度请控制在 1 至 250 位" : GetValue = False : Exit Function
		If Len(vOrder) = 0 Or Not IsNumeric(vOrder) Then LastError = "优先级别只能是数字" : GetValue = False : Exit Function
		If Len(vReplace) = 0 Or Not IsNumeric(vReplace) Then LastError = "替换次数只能是数字" : GetValue = False : Exit Function
		If Len(vTarget) = 0 Or Not IsNumeric(vTarget) Then LastError = "打开方式只能是数字" : GetValue = False : Exit Function
		If Len(vState) = 0 Or Not IsNumeric(vState) Then LastError = "状态只能是数字" : GetValue = False : Exit Function
		GetValue = True
	End Function

	Public Function SetValue()
		Dim Rs
		Set Rs = DB("Select * From [{pre}Sitelink] Where [ID]=" & vID,1)
		If Rs.Eof Then Rs.Close : Set Rs = Nothing : LastError = "你所需要查询的记录 " & vID & " 不存在!" : SetValue = False : Exit Function
		vText = Rs("Text")
		vDescription = Rs("Description")
		vLink = Rs("Link")
		vOrder = Rs("Order")
		vReplace = Rs("Replace")
		vTarget = Rs("Target")
		vState = Rs("State")
		Rs.Close : Set Rs = Nothing
		SetValue = True
	End Function

	Public Function Create()
		Dim Rs
		Set Rs = DB("Select [ID] From [{pre}Sitelink] Where [Text]='" & vText & "'",1)
		If Not Rs.Eof Then Rs.Close : Set Rs = Nothing : LastError = "链接文字 的值 " & vText & " 已存在!" : Create = False : Exit Function
		Set Rs = DB("Select * From [{pre}Sitelink]",3)
		Rs.AddNew
		Rs("Text") = vText
		Rs("Description") = vDescription
		Rs("Link") = vLink
		Rs("Order") = vOrder
		Rs("Replace") = vReplace
		Rs("Target") = vTarget
		Rs("State") = vState
		Rs.Update : Rs.Close : Set Rs = Nothing
		Call ClsCache() '# 清空下缓存
		Create = True
	End Function

	Public Function Modify()
		Dim Rs
		Set Rs = DB("Select * From [{pre}Sitelink] Where [ID]=" & vID,3)
		If Rs.Eof Then Rs.Close : Set Rs = Nothing : LastError = "你所需要更新的记录 " & vID & " 不存在!" : Modify = False : Exit Function
		Rs("Text") = vText
		Rs("Description") = vDescription
		Rs("Link") = vLink
		Rs("Order") = vOrder
		Rs("Replace") = vReplace
		Rs("Target") = vTarget
		Rs("State") = vState
		Rs.Update : Rs.Close : Set Rs = Nothing
		Call ClsCache() '# 清空下缓存
		Modify = True
	End Function

	Public Function Delete()
		Call SetValue()
		Call DB("Delete From [{pre}Sitelink] Where [ID]=" & vID ,0)
		Call ClsCache() '# 清空下缓存
		Delete = True
	End Function
	
	Public Function Change()
		Dim GetField
		GetField = Request("Field")
		If Instr(LCase("[Target],[State]"), LCase("[" & GetField & "]")) = 0 Then LastError = "参数出错,无法修改记录!" : Change = False : Exit Function
		Dim Rs
		Set Rs = DB("Select [" & GetField & "] From [{pre}Sitelink] Where [ID]=" & vID,3)
		If Rs.Eof Then
			Rs.Close : Set Rs = Nothing : LastError ="所需要更新的记录不存在!" : Change = False : Exit Function
		Else
			If Rs(GetField) = 0 Then Rs(GetField) = 1 Else Rs(GetField) = 0
			Rs.Update : Rs.Close : Set Rs = Nothing
			Change = True
		End If
	End Function

End Class
%>